from django.contrib import admin

# Register your models here.
from mall.forms import ProductAdminForm
from mall.models import Product, Classify, Tag
from utils.admin_actions import set_invalid, set_valid






@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
    """商品信息管理"""
    list_display = ('name', 'types', 'price', 'status', 'is_valid')
    # 修改分页数据的大小
    list_per_page = 5
    # 设置过滤器
    list_filter = ('status',)
    # 方式1：设置字段在后台 不显示中并不可编辑
    # exclude = ['remain_count']
    # 方式2：设置字段为不可编辑，但可以显示
    readonly_fields = ['remain_count']
    actions = [set_invalid, set_valid]
    # 自定义表单
    form = ProductAdminForm

@admin.register(Classify)
class ClassifyAdmin(admin.ModelAdmin):
    """商品分类管理"""
    list_display = ('parent', 'name', 'code', 'is_valid')
    # 修改分页数据的大小
    list_per_page = 5
    actions = [set_invalid, set_valid]

@admin.register(Tag)
class TagAdmin(admin.ModelAdmin):
    """商品标签管理"""
    list_display = ('name', 'code', 'is_valid')
    # 修改分页数据的大小
    list_per_page = 5
    actions = [set_invalid, set_valid]
